package com.xingkeduo.business.operation.service;

import com.xingkeduo.dao.database.DatabaseAccessObject;
import com.xingkeduo.pojo.query.PostsPermsQuery;
import com.xingkeduo.pojo.table.PostsPermsTable;
import com.xingkeduo.util.tool.CommonUtil;
import com.xingkeduo.util.tool.IdentityUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 文件概述
 *
 * @author wangxilong <wangxilong@xingkeduo.com>
 * @version id:v0.1 ${date}${time}
 * @package BeautyOS
 * @copyright Copyright (c) XKD 2019
 */
@Component
public class PostsPermsService {
    private static final String NAMESPACE = PostsPermsTable.class.getSimpleName();

    @Resource(name = "mysqlOperationDao")
    private DatabaseAccessObject<PostsPermsTable, PostsPermsQuery> dao;

    //查询一条
    public PostsPermsTable selectById(long id) throws Throwable {
        PostsPermsTable postsPermsTable = dao.select(NAMESPACE, id);
        if (!CommonUtil.isEmpty(postsPermsTable))
            return postsPermsTable;
        return null;
    }

    //查询一条
    public PostsPermsTable selectByCode(long code) throws Throwable {
        PostsPermsTable postsPermsTable = dao.select(NAMESPACE, code);
        if (!CommonUtil.isEmpty(postsPermsTable))
            return postsPermsTable;
        return null;
    }

    //查询多条
    public List<PostsPermsTable> selectLists(PostsPermsQuery postsPermsQuery) throws Throwable {
        List<PostsPermsTable> postsPermsTableList = dao.select(NAMESPACE, postsPermsQuery);
        if (!CommonUtil.isEmpty(postsPermsTableList))
            return postsPermsTableList;
        return null;
    }

    //插入
    public int insert(PostsPermsTable postsPermsTable) throws Throwable {
        postsPermsTable.setCode(IdentityUtil.nextId(IdentityUtil.Worker.USER));
        return dao.insert(NAMESPACE, postsPermsTable);
    }

    //更新
    public int update(PostsPermsTable postsPermsTable) throws Throwable {
        return dao.update(NAMESPACE, postsPermsTable);
    }

    //删除
    public int delete(PostsPermsTable postsPermsTable) throws Throwable {
        return dao.update(NAMESPACE, postsPermsTable);
    }
}
